<?php
/**
 * @copyright meila.com
 * @author shaopu@
 * @name
 * @param
 *         $xxx = 作用
 * @static
 *         XXX = 作用
 *
 *
 */
include('../../__global.php');
include_once SERVER_ROOT_PATH.'/include/ml_function_lib.php';
class aj_album_piclist extends ml_controller
{
    protected $_param_check = array(
        'class_id' => array('type'=>ML_DATATYPE_DIGIT, 'is_must'=>true),
        'album_id' => array('type'=>ML_DATATYPE_DIGIT, 'is_must'=>true),    

    );
    protected $_error_msg = array(
        'album_id' => 'album_id',
        'class_id' => 'class_id',    
    );
    private $_uid;
    public function initParam()
    {
        $this->_option['class_id'] = Tool_input::input('class_id','G', '');
        $this->_option['album_id'] = Tool_input::input('album_id','G', '');
        $this->_uid = $this->__visitor['uid'];
    }
    public function checkParam(){
        $this->check_option();
    }
    public function main()
    {
        $this->add_actionlog();
        $album = ml_tool_getdata::lbJsonData('albumpic_album'.$this->_option['album_id'],'albumpic/class_'.$this->_option['class_id']);
        foreach ($album['piclist'] as $value) {
            $pids[]=$value['pic_id'];
            $shares[]=$this->_option['class_id'].'-'.$this->_option['album_id'].'-'.$value['pic_id'];
        }
        $like_cnt_array = $this->get_like($pids);
        $share_cnt_array = $this->get_share($shares);
        $feed_cnt_array = $this->get_feed($pids);
        $like_flag = false;
        if(isset($_COOKIE['LM_UNLOGIN_LIKE'])) {
            $likeids =  explode(',',$_COOKIE['LM_UNLOGIN_LIKE']);
            if(is_array($likeids) && count($likeids)>0)
                $like_flag = true;
        }
        $album_data['album_id'] = $album['album_id'];
        $album_data['title'] = $album['title'];
        $album_data['pic_cnt'] = $album['pic_cnt'];
        foreach($album['piclist'] as $key=>$pic){
            $album_data['piclist'][$key]['pic_id'] = $pic['pic_id'];
            $album_data['piclist'][$key]['img'] = $pic['bimg'];
            $album_data['piclist'][$key]['wbimg'] = $pic['wbimg'];
            $album_data['piclist'][$key]['desc'] = $pic['desc'];
            $tmp_like_cnt = $like_cnt_array[$pic['pic_id']];
            $tmp_share_cnt = $share_cnt_array[$pic['pic_id']];
            $tmp_feed_cnt = $feed_cnt_array[$pic['pic_id']];
            $album_data['piclist'][$key]['like_cnt'] = empty($tmp_like_cnt) ? 0 : $tmp_like_cnt;
            $album_data['piclist'][$key]['share_cnt'] = empty($tmp_share_cnt) ? 0 : $tmp_share_cnt;
            $album_data['piclist'][$key]['feed_cnt'] = empty($tmp_feed_cnt) ? 0 : $tmp_feed_cnt;
            if($like_flag)
                $album_data['piclist'][$key]['is_like'] = in_array($pic['pic_id'], $likeids); 
        }
        
        $this->api_output(ML_RCODE_SUCC, $album_data);
    }
    private function add_actionlog(){
        //行为日志
        $ext = array(
            'class' => $this->_option['class_id'],
            'album' => $this->_option['album_id'],
        );
        ml_tool_actionlog::view_lookbook($this->_uid , 'piclist' , $ext);
    }
    private function get_like($pids){
        $oMeilaPic = new ml_model_admin_dbMeilaPic();
        $rs = $oMeilaPic->getPicByPids($pids);
        foreach ($rs as $k => $value) {
            $likeCnt[$k] = gb_function_lib::getVitrulCnt($value['pic_id'],$value['like_visitor'] + $value['like_user']);
        }
        return $likeCnt;
    }
    private function get_share($shares){
        $oMcWeibo = new ml_model_album_mcWeiboShare();
        $rs = $oMcWeibo->getShare($shares);
        foreach ($rs as $k => $value) {
            $tmp=explode("-", $k);
            $shareCnt[$tmp[2]] = $value;
        }
        return $shareCnt;
    }
    private function get_feed($pic_ids){
        $oRdsCount = new ml_model_rdsCount();
        return $oRdsCount->getPicAlbumfeedCntByPids($pic_ids);
    }
}
new aj_album_piclist();
?>